//@author A0101906R
#include "Task.h"
#include <sstream>
using namespace Twentyfifth;
using namespace std;

Task::Task() {
	taskType = INVALID;
	id = 0;
	gcal_id = BLANK_STRING;
	done = false;
	isDeleted = false;
	gcal_fullday = false;
}

Task::TaskType Task::identifyTaskType(string s) {
	if (s == STRING_TASKTYPE_TIMED) {
		return TIMED_TASK;
	} else if (s == STRING_TASKTYPE_DEADLINE) {
		return DEADLINE_TASK;
	} else if (s == STRING_TASKTYPE_TODO) {
		return TASK;
	} else if (s == "QUERY") {
		return QUERY;
	} else {
		return INVALID;
	}
}

void Task::setDescription(string newDescription) {
	description = newDescription;
}

void Task::setVenue(string newVenue) {
	venue = newVenue;
}

void Task::setId(int newId) {
	id = newId;
}


string Task::getDescription() {
	return description;
}


string Task::getVenue() {
	return venue;
}

int Task::getId() {
	return id;
}

//All the removed functions

void Task::print() {
	cout << description << endl;
	start.print();
	end.print();
}


string Task::toString() {
	switch (taskType) {
	case Task::TIMED_TASK:
		return toStringTimed();
		break;
	case Task::DEADLINE_TASK:
		return toStringDeadline();
		break;
	case Task::TASK:
		return toStringTask();
		break;
	case Task::QUERY:
		return toStringQuery();
		break;
	default:
		return "invalid TaskType";
		break;
	}
}

string Task::toStringTimed() {
	//to convert id to string, so that it can be put into feedback.
	ostringstream convert;
	string ids;
	convert << id << endl;
	ids = convert.str();

	string startString = start.toString();
	string endString = end.toString();
	string feedback = BLANK_STRING;
	if (id) {
		feedback = "Task ID: " + ids;
	}
	feedback = feedback + "Description: " + description + "\n";
	feedback = feedback + "Start: " + startString + "\n";
	feedback = feedback + "End: " + endString + "\n";
	feedback = feedback + "Venue: " + venue + "\n";
	return feedback;
}

string Task::toStringDeadline() {
	ostringstream convert;
	string ids;
	convert << id << endl;
	ids = convert.str();

	string deadlineString = deadline.toString();
	string feedback = BLANK_STRING;
	if (id) {
		feedback = "Task ID: " + ids;
	}
	feedback = feedback + "Description: " + description + "\n";
	feedback = feedback + "Deadline: " + deadlineString + "\n";
	feedback = feedback + "Venue: " + venue + "\n";
	if (done) {
		feedback = feedback + "State: " + "[x] DONE \n";
	} else {
		feedback = feedback + "State: " + "[ ] \n";
	}
	return feedback;
}

string Task::toStringTask() {
	ostringstream convert;
	string ids;
	convert << id << endl;
	ids = convert.str();

	string feedback = BLANK_STRING;
	if (id) {
		feedback = "Task ID: " + ids;
	}
	feedback = feedback + "Description: " + description + "\n";
	if (done) {
		feedback = feedback + "State: " + "[x] DONE \n";
	} else {
		feedback = feedback + "State: " + "[ ] \n";
	}
	return feedback;
}

string Task::toStringQuery() {
	char buffer[500];
	sprintf_s(buffer, "Id: %d\n", id);
	string feedback = buffer;
	feedback = feedback + "Description: " + description + "\n";
	return feedback;
}

vector<string> Task::toStringVector() {
	switch (taskType) {
	case Task::TIMED_TASK:{
							  return toStringTimedVector();
	}
	case Task::DEADLINE_TASK:{
								 return toStringDeadlineVector();
	}
	case Task::TASK:{
						return toStringTaskVector();
	}
	default:{
				vector<string> feedback;
				feedback.push_back("invalid TaskType");
				return feedback;
	}
	}
}

vector<string> Task::toStringTimedVector() {
	vector<string> feedbackVector;
	feedbackVector.push_back("TIMED_TASK");
	string startString = start.toString();
	string endString = end.toString();
	string feedback = "Description: " + description;
	feedbackVector.push_back(feedback);
	feedback = "Start: " + startString;
	feedbackVector.push_back(feedback);
	feedback = "End: " + endString;
	feedbackVector.push_back(feedback);
	return feedbackVector;
}

vector<string> Task::toStringDeadlineVector() {
	vector<string> feedbackVector;
	feedbackVector.push_back("DEADLINE_TASK");
	string deadlineString = deadline.toString();
	string feedback = "Description: " + description;
	feedbackVector.push_back(feedback);
	feedback = "Deadline: " + deadlineString;
	feedbackVector.push_back(feedback);
	return feedbackVector;
}

vector<string> Task::toStringTaskVector() {
	vector<string> feedbackVector;
	feedbackVector.push_back("FLOATING_TASK");
	string feedback = "Description: " + description;
	feedbackVector.push_back(feedback);
	return feedbackVector;
}



Task::TaskType Task::getTaskType() {
	return taskType;
}

DateTime Task::getStart() {
	return start;
}

DateTime Task::getEnd() {
	return end;
}

DateTime Task::getDeadline() {
	return deadline;
}




bool Task::isDone() {
	return done;
}



void Task::setTaskType(string newActionType) {
	taskType = identifyTaskType(newActionType);
}

void Task::setTaskType(Task::TaskType newActionType) {
	taskType = newActionType;
}

void Task::setStart(DateTime newStart) {
	start = newStart;
}

void Task::setEnd(DateTime newEnd) {
	end = newEnd;
}

void Task::setDeadline(DateTime newDeadline) {
	deadline = newDeadline;
}

void Task::setDone() {
	done = true;
}

void Task::setUndone() {
	done = false;
}

void Task::setToggle() {
	doneToggle = true;
}

void Task::setGCalId(string s) {
	gcal_id = s;
}

string Task::getGCalId() {
	return gcal_id;
}

void Task::setDeleted(bool answer) {
	isDeleted = answer;
}

void Task::setLastUpdated(DateTime newLastUpdated) {
	lastUpdated = newLastUpdated;
}

DateTime Task::getLastUpdated() {
	return lastUpdated;
}

bool Task::getDeleted() {
	return isDeleted;
}

void Task::setFullDay(bool boolean) {
	gcal_fullday = boolean;
}

bool Task::isFullDay() {
	return gcal_fullday;
}